<!--
 * @copyright: Huang Ding
 * @Author: ding-cx
 * @Date: 2020-11-10 12:10:01
 * @LastEditors: ding-cx
 * @LastEditTime: 2021-03-22 15:20:42
 * @Description: file content
-->
<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import { reactive, provide } from "@vue/composition-api";
import { useMessage } from "@/hooks/";
import { vueBus } from "@/plugins/";

export default {
  name: "App",
  setup(props, ctx) {
    const globalConfig = reactive({
      elsize: window.dingAdmin.elsize,
    });
    const message = useMessage(ctx.root);

    provide("globalConfig", globalConfig);
    provide("globalMessage", message);

    return {};
  },
  created() {
    // 监听事件，当请求中发现token失效时，则需要执行退出重新登录的操作。
    vueBus.$on("re-login-by-not-token", async () => {
      // console.log();
      // await this.$store.dispatch("user/logout");
      await this.$store.dispatch('user/resetToken')
      this.$router.push({
        name: "login",
        query: { redirect: this.$route.fullPath },
      });
    });
  },
};
</script>
